package com.ruoyi.web.controller.dgw;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dgw.domain.VeterinaryDrug;
import com.ruoyi.dgw.service.IVeterinaryDrugService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 兽药Controller
 * 
 * @author ll
 * @date 2022-01-07
 */
@RestController
@RequestMapping("/dgw/drug")
public class VeterinaryDrugController extends BaseController
{
    @Autowired
    private IVeterinaryDrugService veterinaryDrugService;

    /**
     * 查询兽药列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:drug:list')")
    @GetMapping("/list")
    public TableDataInfo list(VeterinaryDrug veterinaryDrug)
    {
        startPage();
        List<VeterinaryDrug> list = veterinaryDrugService.selectVeterinaryDrugList(veterinaryDrug);
        return getDataTable(list);
    }

    /**
     * 导出兽药列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:drug:export')")
    @Log(title = "兽药", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VeterinaryDrug veterinaryDrug)
    {
        List<VeterinaryDrug> list = veterinaryDrugService.selectVeterinaryDrugList(veterinaryDrug);
        ExcelUtil<VeterinaryDrug> util = new ExcelUtil<VeterinaryDrug>(VeterinaryDrug.class);
        return util.exportExcel(list, "兽药数据");
    }

    /**
     * 获取兽药详细信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:drug:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(veterinaryDrugService.selectVeterinaryDrugById(id));
    }

    /**
     * 新增兽药
     */
    @PreAuthorize("@ss.hasPermi('dgw:drug:add')")
    @Log(title = "兽药", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VeterinaryDrug veterinaryDrug)
    {
        return toAjax(veterinaryDrugService.insertVeterinaryDrug(veterinaryDrug));
    }

    /**
     * 修改兽药
     */
    @PreAuthorize("@ss.hasPermi('dgw:drug:edit')")
    @Log(title = "兽药", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VeterinaryDrug veterinaryDrug)
    {
        return toAjax(veterinaryDrugService.updateVeterinaryDrug(veterinaryDrug));
    }

    /**
     * 删除兽药
     */
    @PreAuthorize("@ss.hasPermi('dgw:drug:remove')")
    @Log(title = "兽药", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(veterinaryDrugService.deleteVeterinaryDrugByIds(ids));
    }
}
